修 test
回到 rainbow/test/application_test.rb
這邊有許多地方都需要被修正
我們用 TestController 來處理吧
注意,他必須繼承 Rulers::Controller
require_relative "test_helper"
class TestController < Rainbow::Controller
  def index
    "Hello!"  # 不會渲染在 view 上
  end
end
class TestApp < Rainbow::Application
def get_controller_and_action(env)
  [TestController, "index"]
  end 
end
class RainbowAppTest < Minitest::Test
  include Rack::Test::Methods
  def app
    TestApp.new
  end
  def test_request
    get "/example/route"
    assert last_response.ok?
    body = last_response.body
    assert body["Hello"]
  end 
end
現在,我們來更新你的其他測試
我們可以在 view 裡面帶入變數
並且讓他渲染在畫面中
還記得我們傳送 env 到 Erubis 嗎?
env 實際上是可以作為一個 view 的變數
讓我們來看下面的例子
# best_quotes/app/views/a_quote.html.erb
<p>
  There is nothing either good or bad but
  <%= @name %> makes it so.
</p>
<p>
  Ruby version <%= env["PATH_INFO"] %>
</p>
讓我們來把下列這段程式碼加到 Rakefile 中
# Rakefile
  require "bundler/gem_tasks"
  require "rake/testtask"
  Rake::TestTask.new do |t|
    t.name = "test"  # this is the default
    t.libs << "test"  # load the test dir
    t.test_files = Dir['test/*test*.rb']
    t.verbose = true
  end
下 rake -T 會秀出 rake 測試後的資料
# Running tests:
.
Finished tests in 0.011220s, 96.9444 tests/s,
195.8864 assertions/s.
1 tests, 2 assertions, 0 failures, 0 errors, 0 skips
在同一個 Ruby 程序中, Rake 會一直跑你的測試
這比在單個進程中要快得多,但這也代表你的測試可能會干擾到其他的程序